package com.mop.sg2.map;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolDecoderAdapter;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

public class GameDecoder extends ProtocolDecoderAdapter {

	@Override
	public void decode(IoSession arg0, IoBuffer arg1, ProtocolDecoderOutput arg2)
			throws Exception {
		int length = arg1.getShort();
		System.out.println("length====" + length);
		IoBuffer data = IoBuffer.allocate(length);
		data.put(arg1);
		// MessageExample a = new MessageExample();
		// a.init(data);

		// 解析LoginMsg
		LoginMsg msg = new LoginMsg();
		msg.init(data);
		
		//发送用户信息
		if ("jay".equals(msg.getName()) && "aaa".equals(msg.getPassword())) {
			RoleInfoMsg roleInfo = new RoleInfoMsg();
			roleInfo.setLevel(10);
			roleInfo.setRoleArmyName("测试军团");
			roleInfo.setRoleName("西楚霸王");
			roleInfo.setRoleNation((short)1);
			if(MessageHandle.session!=null){
				MessageHandle.session.write(roleInfo);
			}
		}
	}

}
